<template>
    <div>
        <h1>房间信息修改</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>房间名称</td>
                    <td>
                        <input type="text" v-model="data.name">
                    </td>
                </tr>
                 <tr>
                    <td>类型</td>
                    <td>
                       <select v-model="data.roomtypeId">
                        <option value="0">请选择</option>
                        <option v-for="a in swert" :value="a.roomtypeId">{{a.name  }}</option>
                       </select>
                    </td>
                </tr>
                   <tr>
                    <td>房号</td>
                    <td>
                       <select v-model="data.roomid">
                        <option value="0">请选择</option>
                        <option v-for="b in swery" :value="b.roomid">{{ b.name }}</option>
                       </select>
                    </td>
                </tr>
                 <tr>
                    <td>地址</td>
                    <td>
                        <input type="text" v-model="data.addr">
                    </td>
                </tr>
                 <tr>
                    <td>电话</td>
                    <td>
                        <input type="text" v-model="data.phone">
                    </td>
                </tr>
                 <tr>
               
                    <td colspan="2">
                        <input type="button" value="修改" @click="Add">
                    </td>
                </tr>
            </thead>
        </table>
    </div> 
</template>

<script setup lang="ts">
import {ref,onMounted} from "vue"
import axios from "axios";
import { useRoute } from "vue-router";
const route=useRoute()
const Fantian=()=>{
    var x=route.query.id
    axios.get("https://localhost:7102/api/Room/Fantian",{params:{id:x}}).then(res=>{
        data.value=res.data
    })
}
const data=ref({
    "id": 0,
  "name": "",
  "roomtypeId": 0,
  "roomid": 0,
  "addr": "",
  "phone": ""
})
const Add=()=>{
    axios.put("https://localhost:7102/api/Room/UptRoom",data.value).then(res=>{
      
         if(res.data>0){
            alert('修改成功');
            location.href='/ShowView';
         
        }
        else{
            alert('添加失败');
        }
    })
}
onMounted(()=>{
    XIala()
    Xialak()
    Fantian()
})
const swert=ref([{
    "roomtypeId": 0,
    "name": "string"
}])
const XIala=()=>{
    axios.get("https://localhost:7102/api/Room/Xiala").then(res=>{
        swert.value=res.data
    })
}
const swery=ref([{
  "roomid": 0,
    "name": "string"
}])
const Xialak=()=>{
    axios.get("https://localhost:7102/api/Room/Xialak").then(res=>{
        swery.value=res.data
    })
}

</script>

<style scoped>

</style>